function ListNode(val) {
    this.val = val;
    this.next = null;
}
var deleteNode = function(head, val) {
    let pre = head
    let cur = head
    while (cur != null) {
        cur.next = head.next
        if (cur.val == val) {
            pre.next = cur.next
        }
        pre = pre.next
        cur = cur.next
    }
    return head

};
let head = new ListNode(1)
head.next = new ListNode(2)
head.next.next = new ListNode(3)
head.next.next.next = new ListNode(4)
let val  = 2
console.log(deleteNode(head, val))